package com.ems.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * @author:zzh。。
 * @create: 2022-06-26 09:56
 * @Description: 代码生成器
 */
public class CodeHelp {
    public static void main(String[] args) {
        generate();
    }
    private static void generate() {
        FastAutoGenerator.create("jdbc:mysql://159.75.96.99:3306/ems?serverTimezone=GMT%2b8", "root", "59454641zh")
                .globalConfig(builder -> {
                    builder.author("ZZH") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("C:\\Users\\zzh\\Desktop\\test\\ems-system-master\\ems-system-master\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.ems") // 设置父包名
                            .moduleName(null) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "C:\\Users\\zzh\\Desktop\\test\\ems-system-master\\ems-system-master\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder().enableLombok();
                    builder.mapperBuilder().enableMapperAnnotation().build();
                    builder.controllerBuilder().enableHyphenStyle()  // 开启驼峰转连字符
                            .enableRestStyle();  // 开启生成@RestController 控制器
                    builder.addInclude("t_emp","t_machine","t_material","t_menu","t_menu_role","t_monitoring_pressure","t_monitoring_temperature","t_order",
                            "t_pressure_curve","t_product","t_product_line",
                            "t_roler","t_temperature_curve",
                            "t_user","t_user_role"
                    ); // 设置需要生成的表名
                    // .addTablePrefix("sys_"); // 设置过滤表前缀
                })
//                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
